<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Message Mailboxes</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="kvaser.gif"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('page_user_guide_send_recv_mailboxes.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Message Mailboxes </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Some other CAN driver libraries in the market feature what usually is called "mailboxes", "message objects", "user buffers" etc. CANlib, on the other hand, focuses on message queues because we feel this imposes fewer restrictions on the CAN system.</p>
<p>For example, a higher layer protocol that uses a sequence of CAN messages with the same identifier is hard to implement using mailboxes: when the next message arrives it overwrites the previous one. You can, in a way, simulate the behavior of mailboxes by using <a class="el" href="group___c_a_n.html#gafb5e475233ef14ccf9084f610caba560">canReadSpecific()</a>. You will have to call <a class="el" href="group___c_a_n.html#ga157d49a9343dea68ac953145e02266d8">canRead()</a> periodically in order to clear out messages not read by <a class="el" href="group___c_a_n.html#gafb5e475233ef14ccf9084f610caba560">canReadSpecific()</a>.</p>
<p><b>Example</b>. How to simulate a mailbox-style CAN interface.</p>
<p>Assume you take special interest in CAN messages with identifiers 530, 540 and 550. Your message-handling loop could then look something like this:</p>
<div class="fragment"><div class="line"><span class="keywordflow">while</span> (..) {</div><div class="line">  <span class="keywordflow">if</span> (<a class="code" href="group___c_a_n.html#gafb5e475233ef14ccf9084f610caba560">canReadSpecific</a>(hnd, 530, buf, ...) == canOK) {</div><div class="line">    <span class="comment">// Process msg 530</span></div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (<a class="code" href="group___c_a_n.html#gafb5e475233ef14ccf9084f610caba560">canReadSpecific</a>(hnd, 540, buf, ...) == canOK) {</div><div class="line">    <span class="comment">// Process msg 540</span></div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (<a class="code" href="group___c_a_n.html#gafb5e475233ef14ccf9084f610caba560">canReadSpecific</a>(hnd, 550, buf, ...) == canOK) {</div><div class="line">    <span class="comment">// Process msg 550</span></div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">while</span> (<a class="code" href="group___c_a_n.html#ga157d49a9343dea68ac953145e02266d8">canRead</a>(hnd, &amp;<span class="keywordtype">id</span>, buf, ...) == canOK) {</div><div class="line">    <span class="comment">// Handle other messages</span></div><div class="line">  }</div><div class="line">}</div></div><!-- fragment --><p>You can call this message-processing routine from your <code>WM__CANLIB</code> handler or make it the main routine in your program.</p>
<h1><a class="anchor" id="section_user_guide_send_recv_queue_and_buf_sizes"></a>
Message Queue and Buffer Sizes</h1>
<p>Incoming and outgoing CAN messages can be buffered in three different places:</p><ul>
<li>In the CAN controller</li>
<li>On the CAN board</li>
<li>In the CAN driver (i.e. CANlib)</li>
</ul>
<p>The sizes of the first two buffers are clearly hardware dependent. You might find the following information useful.</p>
<p>Many CAN boards from KVASER uses the SJA1000 CAN controller. This chip can buffer somewhere between 5 and 19 incoming messages. It does not buffer outgoing messages.</p>
<p>CAN boards with an on-board microcontroller (LAPcan, LAPcan II, USBcan) typically buffer something like 500 incoming and outgoing messages.</p>
<p>CAN boards using the M16C microcontroller (USBcan Rugged, USBcan II, PCIcan II) typically buffer some 100 incoming messages and around 50 outgoing messages.</p>
<p>CANlib <em>drivers</em> will, by default, buffer 256 outgoing messages per channel and 1024 incoming messages per channel. You can use <a class="el" href="group__can__general.html#gaeaa24db97af22478ca51d48636c7bb12">canIoCtl()</a> to adjust the size of the receive buffer. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="page_canlib.html">CAN bus API (CANlib)</a></li>
    <li class="footer"> (canlib 5.38) Tue Feb 15 2022</li>
  </ul>
</div>
</body>
</html>
